public class Solution {
    public int numberOfArithmeticSlices(int[] nums) {
        int len = nums.length;

        if (len <= 2) {
            return 0;
        }

        //以i为结尾的等差数列的个数
        int[] dp = new int[len];

        for (int i = 2; i < len; i++) {
            dp[i] = nums[i] - nums[i - 1] == nums[i - 1] - nums[i - 2] ? dp[i - 1] + 1 : 0;
        }

        int ret = 0;

        for (int num : dp) {
            ret += num;
        }

        return ret;
    }
}
